package yunhe.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BaseFilter implements Filter {

	
	public void destroy() {
		

	}


	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;  
        HttpServletResponse response = (HttpServletResponse) resp;
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String path=request.getServletPath();//获取除工程名之外的路径字符串   以/ 开头
       
        if(blackList.contains(path)){ //黑名单里边含有，跳转的首页
        	response.sendRedirect(request.getContextPath()+"/GetNews"); //获取工程名
        }
        else{
        	chain.doFilter(req, resp);
        }
	}

	List<String> blackList=new ArrayList<String>();
	public void init(FilterConfig arg0) throws ServletException {
		blackList.add("/footer.jsp");
		blackList.add("/header.jsp");
	}

}
